package com.my.lucky.repository;

import com.my.lucky.model.StockMainCost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;

@Repository
public interface StockMainCostRepository extends JpaRepository<StockMainCost, Long> {

    // 根据日期删除数据
    void deleteBySearchDate(LocalDate searchDate);

    // 根据日期查询数据
    List<StockMainCost> findBySearchDate(LocalDate searchDate);

    // 删除所有早于指定日期的数据（新增方法）
    @Transactional
    void deleteBySearchDateBefore(LocalDate date);

    // 根据股票代码和日期查询
    @Query("SELECT s FROM StockMainCost s WHERE s.stockCode = :code AND s.searchDate = :date")
    StockMainCost findByCodeAndDate(@Param("code") String code, @Param("date") LocalDate date);
}
